from utils.JSON的输入和输出 import 写入json, 读取json

# ! 这个文件不一定要执行...

card_desc_zh = 读取json('data/卡片效果/中文/CARD_Desc.json')
card_desc_jp = 读取json('data/卡片效果/日语/CARD_Desc.json')

dlg_text = 读取json('output/JSON/DLG_Text.json')


def startWithNum(s: str) -> bool:
    nums = ['①', '②', '③', '④']
    return s[0] in nums


def divideDesc(s: str) -> list:
    separators = ['①', '②', '③', '④']
    res = []
    for i in range(len(s)):
        if i == 0 or s[i] in separators:
            res.append(s[i])
        elif s[i] == '\n' or s[i] == '\r':
            continue
        else:
            res[-1] += s[i]
    return [
        item for item in res
        if item[0] in separators and len(item) > 1 and item[1] == '：'
    ]


# print(
#     divideDesc(
#         '4星怪兽×2\r\n这个卡名的①②的效果1回合只能有1次使用其中任意1个。\r\n①：把这张卡1个超量素材取除，以场上1只表侧表示怪兽为对象才能发动。那只怪兽变成里侧守备表示。\r\n②：把这张卡2个超量素材取除，以这张卡以外的场上1张表侧表示的卡为对象才能发动。那张卡回到持有者卡组。'
#     ))

cnt = 0
for item in dlg_text:
    if len(item['word']) > 5 and startWithNum(item['word']) and not item['trans']:
        # print('这是一个word', item['word'])
        # 在日语中搜对应的
        for i, desc_jp in enumerate(card_desc_jp):
            if item['word'] in desc_jp:
                # print(i)
                # print("日文", item['word'])
                # 找到了
                desc_zh = card_desc_zh[i]
                num = item['word'][0]
                for word in divideDesc(desc_zh):
                    if word[0] == num:
                        item['trans'] = word
                        # print("中文", word)
                        break
                break
        cnt += 1
        print(cnt)
        # if cnt == 10:
        #     break

写入json(dlg_text, 'output/JSON/DLG_Text.json')
